<template>
  <div class="login">
    <div class="myLogin" align="center">
      <h4>注册</h4>
      <el-form :model="registerForm" :rules="registerRules" ref="loginForm" label-width="0px">
        <el-form-item label="" prop="username" style="margin-top: 30px">
          <el-row>
            <el-col :span="2">
              <span style="margin-right: 50px" class="el-icon-s-custom"></span>
            </el-col>
            <el-col :span="22">
              <el-input placeholder="用户名" v-model="registerForm.username"></el-input>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="" prop="password">
          <el-row>
            <el-col :span="2">
              <span style="margin-right: 50px" class="el-icon-lock"></span>
            </el-col>
            <el-col :span="22">
              <el-input type="password" placeholder="密码" v-model="registerForm.password"></el-input>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="" prop="password">
          <el-row>
            <el-col :span="2">
              <span style="margin-right: 50px" class="el-icon-lock"></span>
            </el-col>
            <el-col :span="22">
              <el-input type="password" placeholder="确认密码" v-model="registerForm.confirmPassword"></el-input>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item style="margin-top: 55px">
          <el-button type="primary" round class="submitBtn" @click="submitForm">注册</el-button>
        </el-form-item>
        <div>
          <router-link :to="{ path: '/register' }">
            <router-link to="/login" target="_blank" align="right"></router-link>
          </router-link>
        </div>
      </el-form>
    </div>
  </div>
</template>


<script>
import {getRegisterStatus} from "../api/index";

export default {
  name: "Register",
  data: function () {
    return {
      registerForm: {
        username: '',
        password: '',
        confirmPassword: '',
      },
      registerRules: {
        username: [{required: true, message: "请输入账号", trigger: "blur"}],
        password: [{required: true, message: "请输入密码", trigger: "blur"}],
        confirmPassword: [{required: true, message: "请确认密码", trigger: "blur"}]
      },
    };
  },
  methods: {
    submitForm: function () {
      const userAccount = this.registerForm.username;
      const userPassword = this.registerForm.password;
      const confirmUserPassword = this.registerForm.confirmPassword;
      if (!userAccount) {
        return this.$message({
          type: "error",
          message: "账号不能为空！",
        });
      }
      if (!userPassword) {
        return this.$message({
          type: "error",
          message: "密码不能为空！",
        });
      }
      if (userPassword !== confirmUserPassword) {
        this.$message.error("两次输入的密码不一致")
        return false
      }
      getRegisterStatus(userAccount, userPassword)
        .then((res) => {
          if (res.code === 200) {
            return this.$message({
              type: "success",
              message: "注册成功！",
            }),
              this.$router.push("/");
          } else {
            return this.$message({
              type: "error",
              message: "注册失败！",
            });
          }
        })

    },
  },
};
</script>
<style scoped>

.login {
  position: relative;
  background: url("../assets/img/evbhbrvt3xmevbhbrvt3xm.jpg");
  background-attachment: fixed;
  background-position: center;
  background-size: cover;
  width: 100vw;
  padding: 0;
  margin: 0;
  height: 100vh;
  font-size: 16px;
  background-position: left top;
  color: #fff;
  font-family: "Source Sans Pro";
  position: relative;

}

.myLogin {
  width: 240px;
  height: 280px;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  padding: 50px 40px 40px 40px;
  box-shadow: -15px 15px 15px rgba(6, 17, 47, 0.7);
  opacity: 1;
  background: linear-gradient(
    230deg,
    rgba(53, 57, 74, 0) 0%,
    rgb(0, 0, 0) 100%
  );
}

.inps input {
  border: none;
  color: #fff;
  background-color: transparent;
  font-size: 12px;
}

.submitBtn {
  background-color: transparent;
  color: #39f;
  width: 200px;
}
</style>
